home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / Takeover / propjoy.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.7 KB  |  221 lines

  1. /******************************************************************************
  2. *
  3. *   Source Control
  4. *   --------------
  5. *   $Header: propjoy.c,v 34.1 85/11/24 17:59:44 bart Exp $
  6. *
  7. *   $Locker:  $
  8. *
  9. *   $Log:   propjoy.c,v $
  10. *   Revision 34.1  85/11/24  17:59:44  bart
  11. *   be system compatible
  12. *   
  13. *   Revision 34.0  86/11/21  16:35:51  bart
  14. *   added to rcs for updating
  15. *
  16. * Copyright (c) 1988 Commodore-Amiga, Inc.
  17. * Executables based on this information may be used in software
  18. * for Commodore Amiga computers.  All other rights reserved.
  19. * This information is provided "as is"; no warranties are made.
  20. * All use is at your own risk, and no liability or responsibility is assumed.
  21. *
  22. ******************************************************************************/
  23.  
  24. /* main.c - test program for add/rem tof task - bart - 05.19.86 */
  25. /* propjoy.c modified program for proportional controller - bart - 11.21.86 */
  26.  
  27. #include <exec/types.h>
  28. #include <exec/nodes.h>
  29. #include <exec/execbase.h>
  30. #include <exec/execname.h>
  31.  
  32. #include <graphics/gfxbase.h>
  33. #include <graphics/graphint.h>
  34.  
  35. #include <hardware/cia.h>
  36. #include <hardware/custom.h>
  37. #include <hardware/intbits.h>
  38.  
  39. #include <resources/potgo.h>
  40.  
  41. #define V1_POINT_2  33
  42.  
  43. #define NUM_SERVERS 2
  44.  
  45. #define MAX_COUNT   (UWORD)~1        /* do it for a while */
  46.  
  47. /* use system defined hard addresses */
  48.  
  49. extern struct Custom custom;
  50.  
  51. /* use system defined addresses for potgo and pot1dat */
  52.  
  53. #define POTGO        &custom.potgo
  54. #define POT0DAT        &custom.pot0dat
  55. #define POT1DAT        &custom.pot1dat
  56.  
  57. /* vertical blank interrupt server priority   */
  58.  
  59. #define HIGHINTPRI 127L        /* needs to be replaced with priority relative */
  60. #define LOWINTPRI -127L        /* needs to be replaced with priority relative */
  61.  
  62. /* bit number defines for potgo ... */
  63.  
  64. #define START_B        0    
  65.  
  66. #define DATRX_B        8    
  67. #define DATRY_B        10
  68.  
  69. #define DATLX_B        12    
  70. #define DATLY_B        14
  71.  
  72. /* masks ... */
  73.  
  74. #define START_F        (1L << START_B)
  75. #define DATRX_F        (1L << DATRX_B)
  76. #define DATRY_F        (1L << DATRY_B) 
  77. #define DATLX_F        (1L << DATLX_B)
  78. #define DATLY_F        (1L << DATLY_B) 
  79.  
  80. #define RPOTX        (START_F | DATRX_F) 
  81. #define RPOTY        (START_F | DATRY_F) 
  82. #define RPOTXY        (START_F | DATRX_F | DATRY_F) 
  83.  
  84. #define LPOTX        (START_F | DATLX_F) 
  85. #define LPOTY        (START_F | DATLY_F) 
  86. #define LPOTXY        (START_F | DATLX_F | DATLY_F) 
  87.  
  88. struct ExecBase *ExecBase = NULL;
  89. struct GfxBase *GfxBase = NULL;
  90. struct PotgoBase *PotgoBase = NULL;
  91.  
  92. /* global storage for potdat */
  93.  
  94. UWORD oldbits = NULL;
  95. UWORD potbits = NULL;
  96. ULONG potdat = NULL;
  97.  
  98. /* create server-task to read the proportional joysticks,*/ 
  99. /* update potdat, and then poke potgo to start next data read */
  100.  
  101. /* reserve space for the interrupt servers */
  102. struct Isrvstr server[NUM_SERVERS] = {NULL};
  103.  
  104. first_server(i)
  105. int i;
  106. {
  107.     /* read previous proportional joystick values */
  108.     potdat = *(ULONG *)POT0DAT;
  109.  
  110.     /* poke potgo, restore old bits */
  111.     WritePotgo(oldbits,((~1)<<8)|oldbits);
  112.  
  113.     /* be nice -- let other servers run, too */
  114.     return(NULL);
  115. }
  116.  
  117. second_server(i)
  118. int i;
  119. {
  120.     /* poke potgo, start prop joystick read  */
  121.     WritePotgo(potbits,((~1)<<8)|potbits);
  122.  
  123.     /* be nice -- let other servers run, too */
  124.     return(NULL);
  125. }
  126.  
  127.  
  128. main()
  129. {
  130.     LONG error = FALSE;
  131.     struct Isrvstr *iserver[NUM_SERVERS];
  132.     LONG i;
  133.  
  134.     /* set server priorities */ 
  135.     server[0].is_Node.ln_Pri = HIGHINTPRI;  
  136.     server[1].is_Node.ln_Pri = LOWINTPRI;   
  137.  
  138.     /* set up server pointers */
  139.     iserver[0] = &server[0];
  140.     iserver[1] = &server[1];
  141.  
  142.     if((ExecBase = (struct ExecBase *)OpenLibrary(EXECNAME,V1_POINT_2)) != NULL)
  143.     {
  144.     if((GfxBase = (struct GfxBase *)
  145.         OpenLibrary("graphics.library",V1_POINT_2)) != NULL)
  146.     {
  147.  
  148.         if((PotgoBase = OpenResource(POTGONAME,V1_POINT_2)) != NULL)
  149.         {
  150.  
  151.         /* remember currently used bits */
  152.         oldbits = ~(AllocPotBits(~1));
  153.  
  154.         /* restore previous state of bit allocation */
  155.         FreePotBits(~oldbits);
  156.  
  157.         /* now attempt to allocate start potbit */
  158.         potbits = AllocPotBits(START_F);
  159.  
  160.         Forbid();   
  161.  
  162.         /* add interrupt servers */
  163.  
  164.         AddTOF(iserver[0],first_server,0);
  165.  
  166.         AddTOF(iserver[1],second_server,1);
  167.  
  168.         Permit();
  169.  
  170.         /* loop until done */
  171.  
  172.         for(i=0; i < MAX_COUNT; i++)
  173.         {
  174.             /* wait for server to update pot values */
  175.             WaitTOF();
  176.  
  177.             /* only output information once every second */
  178.             if(!(i %  ExecBase->VBlankFrequency))
  179.             {
  180.             }
  181.         }
  182.  
  183.         Forbid();   
  184.  
  185.         for(i=0; i < NUM_SERVERS; i++)
  186.         {
  187.             RemTOF(iserver[i]);
  188.         }
  189.  
  190.         Permit();
  191.  
  192.         /* free potbits */
  193.  
  194.         FreePotBits(potbits);
  195.  
  196.         CloseLibrary(GfxBase);
  197.         }
  198.         else
  199.         {
  200.         error = TRUE;
  201.         }
  202.     }
  203.     else
  204.     {
  205.         error = TRUE;
  206.     }
  207.  
  208.     CloseLibrary(ExecBase);
  209.  
  210.     }
  211.     else
  212.     {
  213.     error = TRUE;
  214.     }
  215.  
  216.     /* return error code */
  217.     exit(error);
  218. }
  219.